package com.example.test.dto;

import lombok.Data;
import lombok.experimental.Accessors;

/**
 * 日期：2022/11/5
 * 作者：flag
 * 功能：返回值
 */
@Data
@Accessors(chain = true)
public class Result<T> {

    /**
     * 响应编码
     * */
    private int code;

    /**
     * 响应信息
     * */
    private String msg;

    /**
     * 返回数据
     * */
    private T data;

    public Result(ResultCode code, T data) {
        this.code = code.getCode();
        this.msg = code.getMsg();
        this.data = data;
    }

    public static <T> Result<T> success(T data) {
        return new Result<T>(ResultCode.SUCCESS, data);
    }

    public static <T> Result<T> error(T data) {
        return new Result<T>(ResultCode.ERROR, data);
    }

    public static <T> Result<T> error(ResultCode code, T data) {
        return new Result<T>(code, data);
    }
}

